<template>
	<div>
		<item-type-a v-if="itemType == 'A'" :styleConfig="styleConfig" :buttonActive="buttonActive">
		</item-type-a>
		<item-type-b v-if="itemType == 'B'" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">
		</item-type-b>
		<item-type-c v-if="itemType == 'C'" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)" :moreseedata="moreseedata">

		</item-type-c>
		<item-type-d v-if="itemType == 'D'" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">

		</item-type-d>
		<item-type-e v-if="itemType == 'E' && mrender" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">

		</item-type-e>

		<item-type-f v-if="itemType == 'F' && mrender" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">

		</item-type-f>

		<item-type-g v-if="itemType == 'G' && mrender" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">
		</item-type-g>

		<item-type-h v-if="itemType == 'H' && mrender" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">
		</item-type-h>
		<item-type-i v-if="itemType == 'I' && mrender" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">
		</item-type-i>
		<item-type-j v-if="itemType == 'J' && mrender" :styleConfig="styleConfig" :buttonActive="buttonActive" :comInfor="translateDetailData(newDetail)">
		</item-type-j>

  </div>
</template>

<script>
  import ItemTypeA from './ItemTypeA'
  import ItemTypeB from './ItemTypeB'
  import ItemTypeC from './ItemTypeC'
  import ItemTypeD from './ItemTypeD'
  import ItemTypeE from './ItemTypeE'
  import ItemTypeF from './ItemTypeF'
  import ItemTypeG from './ItemTypeG'
  import ItemTypeH from './ItemTypeH'
  import ItemTypeI from './ItemTypeI'
  import ItemTypeJ from './ItemTypeJ'
  import axios from 'axios'
  import  {translateDetailData} from '@/utils/TranslateDetailDate'
	import {mapState, mapGetters, mapActions, mapMutations} from 'vuex';
	import { getHrefParams } from '../../utils/zx'
  export default {
		data() {
			return {
				mrender: true,
				newDetail: this.detail
			}
		},

    components: {
      ItemTypeA,
      ItemTypeB,
      ItemTypeC,
      ItemTypeD,
      ItemTypeE,
      ItemTypeF,
      ItemTypeG,
      ItemTypeH,
      ItemTypeI,
      ItemTypeJ
    },
    props: {
      itemType: {
        default: 'A',
        type: String,
      },
      styleConfig: {
        type: Object,
        default: () => {
          return {}
        }
      },
      detail: {
        type: Object,
        default: () => {
          return {}
        }
      },
      buttonActive: {
        default: null
      },
      moreseedata: {
		type: Object,
		default: () => {}
	  }
	},
	watch: {
		detail(data) {
			if(this.env == 'edit') {
				console.log(data, '数据 走起')
				this.mrender = false;
				setTimeout(() => {
					this.mrender = true;
				}, 5);
			}
		}
	},
	computed:{
		// ...mapState('ly',[`
		// 	'caipin_date'
		// ]),
		env() {
			return window.environment; // 获取是否是编辑状态
		},
	},
	async mounted () {
		if(this.detail.goodsType != 9 ){ return }
		let storeCode = getHrefParams().storeCode;
		console.log('storecode', storeCode);
		let config = {
			url: api.base_host + '/baseStore/getStore',
			method: 'POST',
			data: {
				storeCode: storeCode,
				enterpriseCode: api.enterpriseCode
			}
		}
		let storeStatus = await axios(config);
		storeStatus = storeStatus.data.data[0][0];
		console.log('ressssssss', storeStatus);
		let { dishesTimeJson, dishesTimeIsOpen } = storeStatus;
		dishesTimeJson = JSON.parse(dishesTimeJson);
		if(dishesTimeIsOpen === 0 && dishesTimeJson.length){
			console.log('mounted-has-date')
			this.newDetail = Object.assign({},this.detail,{ stockCount:0 });
			// console.log('清空库存-123',this.newDetail)
			this.getServerTime(dishesTimeJson);
		}
	},
	methods: {
		translateDetailData,
		getServerTime (timeArr) {
			// console.log('菜品限时时间段数据',timeArr);
			let options = {
				url: window.api.base_host + '/baseStore/getServerTime',
				method: "get",
		        params: { token : new Date().getTime() }
			}
			axios(options).then(res => {
				res = res.data;
				let time = res.data[0];
				time = [ new Date(time).getHours(),new Date(time).getMinutes() ];
				let timeFlag = timeArr.some(item => {
						let dishesStartTime = item.dishesStartTime.split(':');
						let dishesEndTime = item.dishesEndTime.split(':');
						let startTime = new Date(2000,1,1,dishesStartTime[0],dishesStartTime[1],0).getTime();
						let nowTime = new Date(2000,1,1,time[0],time[1],0).getTime();
						let endTime = new Date(2000,1,1,dishesEndTime[0],dishesEndTime[1],0).getTime();
						return nowTime >= startTime && nowTime < endTime;
				});
				if(!timeFlag) {
					this.newDetail = Object.assign({},this.detail);
					// console.log('恢复库存',this.newDetail)
				}
			});
		}
	}
  }
</script>

<style>

</style>
